package com.lovetemperature.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@Entity
@Table(name="shops")
public class Shop {
	@Id
	@GeneratedValue
	private Long shopId;
	private String name;
	private String address;
	
	@OneToMany(mappedBy="workingShop",fetch=FetchType.EAGER)
	@Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE})
	private List<Staff> staffList;
	
	@OneToOne
	@Cascade(value=org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	private Staff manager;
	private String phone;
	
	@OneToMany(fetch=FetchType.EAGER, mappedBy="shop")
	private List<Order> orders;	//本店接受的订单
	
	public Shop(){}
	public Long getShopId() {
		return shopId;
	}
	public void setShopId(Long shopId) {
		this.shopId = shopId;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public List<Staff> getStaffList() {
		return staffList;
	}
	public void setStaffList(List<Staff> staffList) {
		this.staffList = staffList;
	}
	public Staff getManager() {
		return manager;
	}
	public void setManager(Staff manager) {
		this.manager = manager;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public List<Order> getOrders() {
		return orders;
	}
	public List<Order> getNonFinishedOrders(){
		List<Order> result = new ArrayList<Order>();
		for(Order order : orders){
			if(!order.getFinished()){
				result.add(order);
			}
		}
		return result;
	}
	public void setOrders(List<Order> orders) {
		this.orders = orders;
	}
}
